package com.lxyk.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lxyk.service.WaterDetailsService;
import com.lxyk.vo.WaterDetails;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@Slf4j
@RequestMapping("/stat")
public class WaterDetailsController {
    @Autowired
    private WaterDetailsService waterDetailsService;
    @RequestMapping("statWaterDetails")
    public String statWaterDetailsService(Model model, WaterDetails waterDetails,
                                            @RequestParam(required = false,defaultValue = "1",value = "pageNum")Integer pageNum,
                                          @RequestParam(defaultValue = "10",value = "pageSize")Integer pageSize){
        if (pageNum == null){
            pageNum = 1;
        }
        if (pageSize == null){
            pageSize = 10;
        }
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<WaterDetails> pageInfo = waterDetailsService.querySendWaterDetails(waterDetails, pageNum, pageSize);
        model.addAttribute("pageInfo",pageInfo);
        model.addAttribute("pageNo",pageInfo.getPageNum());
        model.addAttribute("totalPages",pageInfo.getPages());
        model.addAttribute("pageNums",pageInfo.getNavigatepageNums());
        return "waterDetailsList";
    }
}
